package com.lilicould.controller;

import com.lilicould.service.impl.AccountServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/delete/account")
public class DeleteAccountController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userId = req.getParameter("userId");
        AccountServiceImpl accountService = new AccountServiceImpl();
        boolean result = accountService.deleteAccount(userId);
        if (result) {
            req.getSession().setAttribute("error", "删除成功");
            req.getRequestDispatcher("/employee/info").forward(req, resp);
        }else {
            req.getSession().setAttribute("error", "删除失败");
            req.getRequestDispatcher("/employee/info").forward(req, resp);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
